home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / utility / uuexe656.zip / UUTECH.TXT < prev    next >
Text File  |  1996-11-01  |  17KB  |  398 lines

  1. This file contains a write-up of the more technical aspects of
  2. uuencoding and uudecoding.  First read the file UUSER.TXT, then read
  3. this for more details.
  4.  
  5. Documentation for UUENCODE/DECODE 96 (v56)
  6.  
  7. UU-encoding is a way to code a file which may contain any characters
  8. into a standard character set that can be reliably sent over diverse
  9. networks.
  10.  
  11.  
  12. THE CHARACTER ENCODING:
  13.  
  14. The basic scheme is to break groups of 3 eight bit characters (24 bits)
  15. into 4 six bit characters and then add 32 (a space) to each six bit
  16. character which maps it into a readily transmittable character.  Another
  17. way of phrasing this is to say that the encoded 6 bit characters are
  18. mapped into the set:
  19.         `!"#$%&'()*+,-./012356789:;<=>?@ABC...XYZ[\]^_
  20. for transmission over communications lines.
  21.  
  22. As some transmission mechanisms compress or remove spaces, spaces are
  23. changed into back-quote characters (a 96).  (A better scheme might have
  24. been to use a bias of 33 so a space is not created, but this is not
  25. done.)
  26.  
  27. A newer, less popular, encoding method, called XX-encoding uses the set:
  28.         +-01..89ABC...XYZabc...xyz
  29.  
  30. In my opinion, XX-encoding is superior to UU-encoding because it uses
  31. more "normal" characters that are less likely to get corrupted.  In fact
  32. several of the special characters in the UU set do not get through an
  33. EBCDIC to ASCII translation correctly.  Conversely, an advantage of the
  34. UU set is that it does not use lower case characters.  Now-a-days both
  35. upper and lower case are sent with no problems; maybe in the
  36. communications dark ages, there was a problem with lower case.
  37.  
  38. This "UU" encode/decode pair can handle either XX or UU encoding.  The
  39. encode program defaults to creating a UU encoded file; but can be run
  40. with a "-x" option to create an XX encoding.
  41.  
  42. The decode program defaults to autodetect.  However the program can get
  43. confused by comment lines preceding the actual encoded data.  The decode
  44. mode can be forced to UU or XX with the "-u" or "-x" parameter.
  45.  
  46. Another option is for the character mapping table to be inserted at the
  47. front of the file.  The format for this is discussed later.  A table
  48. is automatically detected and used by this decode program.  (A table
  49. will override the "-x" or "-u" parameters.) The encode program can be
  50. run with a "-t" option which tells it to put the table into the encoded
  51. file.
  52.  
  53. A third encode mapping is the one used by Brad Templeton's ABE program.
  54. This is not handled by these programs as the check and control
  55. information surrounding the actual encoded data is in a different form.
  56.  
  57. From a theoretical view, this encoding is breaking down 24 bits modulo
  58. 64.  Note that 64**3 is = 2**24.  The result is 24 bits in for 32 bits
  59. out, a 33% size increase.  Note that 85**5 > 2**32.  Also note that
  60. there are 94 transmittable ASCII characters (from 0x21 through 0x7e).
  61. Thus modulo 85 encoding (the atob encoder) transforms 32 bits to 5 ASCII
  62. chars or 40 bits for a 25% size increase.
  63.  
  64. The trade off in the modulo 85 encoding is that many communications
  65. systems do not reliably transmit 85 ASCII characters.  The tilde, carat,
  66. brackets, and sometimes upper or lower case, may get corrupted.
  67.  
  68. There are three other popular encoding techniques.  One is BinHex used on
  69. Apple Computers.  The current version is BinHex 4.0.  BinHex uses
  70. another mapping into 64 characters.  The first encoded line in a BinHex
  71. file is an encoded structure that contains the file name, size,
  72. checksum, date and time The remaining lines are encoded data.
  73.  
  74. Another technique that I have seen is BinMail used on Unisys A-series.
  75.  
  76. The most recent mechanism is incorporated into MIME and is called
  77. Base64 encoding.  I support this as a $20 shareware option.  It uses
  78. another character mapping of 64 characters with no checksums and no
  79. special "end" indicator.
  80.  
  81.  
  82. COMPOSING A LINE OF ENCODED CHARACTERS:
  83.  
  84. A small number of eight bit characters are encoded into a single line
  85. and a count is put at the start of the line.  (Most lines in an encoded
  86. file have 60 encoded characters (45 original bytes).  When you look at
  87. a UU-encoded file note that most lines start with the letter "M".  "M"
  88. is decimal 77 in ASCII which, minus the 32 bias, is 45.)
  89.  
  90. BinHex does not use a count character, every encoded line contains 64
  91. characters.  Except the last is limited by the file size.
  92.  
  93. Base64, like BinHex, does not use a count character.  An encoded line
  94. can be any length (modulo 4).  The last line also is module 4 length
  95. but the "=" character indicates no character so the actual file length
  96. can be recreated.
  97.  
  98. This encode program optionally puts a check character at the end of each
  99. line.  The check is the sum of all the encoded characters, before adding
  100. the mapping, modulo 64.
  101.  
  102. Note: Horton 9/1/87 UUENCODE has a bug in the line check algorithm; it
  103. uses the sum of the original, not the encoded characters.  This decode
  104. program accepts either form of line check character.
  105.  
  106. In previous versions  of my package (4.13 and lower) the line check
  107. characters was generated by default by the encode program and was
  108. suppressed with the "-L" option.  One reason to suppress them is if
  109. the decode will be done by one of the old Horton decoders.  Most modern
  110. decoders either accept this form of line level check or will simply stop
  111. looking after the line length is exhausted.  My feelings are mixed about
  112. the current need for line checksums because errors of this type
  113. essentially never occur.
  114.  
  115. Given modern, error-free communications systems and the CRC checks on
  116. the entire file (see below) I have made the default for uuencoding to
  117. have NO line level check characters effective version 4.21.  The "-L"
  118. option on uuencode turns on generation of line checksums.  If you have a
  119. problem communications system and want to isolate the trouble, turn them
  120. on.
  121.  
  122. Uudecode automatically checks for the presence of line checksums; so the
  123. default for uudecode is to leave line level checks on.  If there are some
  124. problems the "-L" option for uudecode turns them off; sometimes there
  125. is junk at the end of the line which causes spurious line checksum
  126. errors.
  127.  
  128. I have encountered various other ways that encoders end lines.  One
  129. encoder put an "M" at both the start and end of the line.  Another used
  130. a line count character.  This decode program checks all of these.  I
  131. would not be surprised if some encoder out there ends lines with
  132. sequential astrological symbols.  If you encounter some other weird form
  133. of encoded file, let me know.  (The -L option turns line level checking
  134. off.)
  135.  
  136.  
  137. PACKAGING THE LINES INTO FILES:
  138.  
  139. The lines of encoded data can be preceded by comments and by network
  140. addressing information.  The encoded data is directly preceded by a line
  141. containing:
  142.  
  143.              begin <file-mode> <file-name>
  144.  
  145. This line is created by the encode program.  The decode program scans
  146. the file looking for "begin" in column 1.  If following line is the
  147. encoded data, the decoding process begins.
  148.  
  149. Some encoders put file time and date information on the begin line:
  150.  
  151.              begin <file-mode> <file-name> <date> <time>
  152.  
  153. My UUdecoder will accept this form of begin line, but does not use the
  154. time and date information.
  155.  
  156. The final end of encoded data is an encoded line with zero encoded
  157. characters (a back-quote), followed by a line containing "end".
  158.  
  159. For integrity checking, some encode programs insert checksums for the
  160. entire file.  This decode tries to check for all known types of file
  161. checksums.  This is discussed in more detail below.
  162.  
  163. This encode program puts a header line, containing the section number
  164. and file name, in front of every section:
  165.  
  166.          "section <number> of <max sections> of file <file name>"
  167.  
  168. At the end of a section the encode program inserts a line containing
  169. checksum and file size information.  This can be suppressed with the
  170. "-c" option.
  171.  
  172. Other encoders use a variety of section lines:
  173.  
  174.         The format of the Archive-name line is:
  175.                 "Archive-name: <name>/part<number>"
  176.         for example:
  177.                 Archive-name: diskutl/part02
  178.  
  179.         The format of the part line is:
  180.                 <name> part<number>/<max-number>
  181.         for example:
  182.                 diskutl part02/03
  183.  
  184.         WinCode uses:
  185.                 [ section: 1/2 file: diskutl.exe . . . .
  186.  
  187.         enuu uses:
  188.                 section 001/002  diskutl.exe  . . . .
  189.  
  190. This program checks for consistency of these names and numbers as of
  191. release 5.0.  The problem is distinguishing random text from valid
  192. lines.
  193.  
  194. For each line that uudecode thinks is a "section" line, tests are made
  195. to validate the current section number, the maximum section number and
  196. the file name.  The program is conservative and may sometimes
  197. erroneously give an "invalid section line" type of error.  Inspect the
  198. file; if uudecode made a mistake, edit or delete the indicated line; and
  199. continue.  If the problem appears to be a uudecode problem, not just
  200. some random comment lines that caused a one time problem, please contact
  201. me.
  202.  
  203. All the "integrity fields" (the checksum, the line check, and the
  204. section header line) are inserted in a way that they will be ignored by
  205. other UUDECODE programs that cannot handle them.  This decode program
  206. does not require any of these fields; if not present, integrity checking
  207. is not done.  This program pair is 100% downward compatible!
  208.  
  209.  
  210. FILE NAMES:
  211.  
  212. See UUSER.TXT for a discussion of file naming conventions.
  213.  
  214.  
  215.  
  216. DECODE and VALID LINES:
  217.  
  218. The below information is to help you solve infrequent problems when
  219. decoding files.  Normally you do not have to be concerned with any of
  220. this stuff.
  221.  
  222. UUdecode sometimes get confused and thinks header lines are encoded
  223. data.  Sometimes this is because the separator line between sections
  224. (the "cut" line) is indistinguishable from valid decodable data.  (An
  225. example is the line "---" used as a cut line on several DOS BBS
  226. systems.) You can tell UUdecode that a specific line is a cut line and
  227. not a decodable line with the -Z option:
  228.  
  229.     uudecode -Z "---" myfile
  230.  
  231. Other times there is not a cut line between file sections or there is
  232. some other problem with the file.  If so, edit the file and try again.
  233.  
  234. When decode encounters a premature end-of-file or some data which is not
  235. decodable, it assumes the end of a file section.  Decode is conservative
  236. when it encounters data it cannot decode (better an error than a bad
  237. file).
  238.  
  239. Usually this undecodable data is valid "trailer" data put at the end of
  240. file for data transmission purposes.  However the file may be bad.  So
  241. decode continues to scan the file, if decode then encounters a line
  242. which is decodable it assumes the file is bad and displays an error
  243. message.
  244.  
  245. When decode encounters a valid end of file section it must get the next
  246. file in sequence.  If the file name ends with a number, decode tries the
  247. next file name in numeric sequence.  Otherwise decode asks for a file
  248. name.  If this file does not contain decodable data, decode asks for
  249. another file to try.
  250.  
  251. If multiple sections are saved in a single file, each section must have
  252. some type of section line for validation.  Decode builds a table of
  253. section information so it can go back and reread if sections are not
  254. saved in order.
  255.  
  256. The "SECTION" line inserted by the UUENCODE program is used for validity
  257. checking only.  If not present, decode will accept any file containing
  258. encoded lines.
  259.  
  260.  
  261. OTHER FILE FORMS:
  262.  
  263. Sometimes files are wrapped in shell archives that automatically check
  264. sequencing and call uudecode for you on Unix systems.  If you prefer to
  265. download the raw files to MS-DOS, uudecode 5.33 will filter simple shell
  266. scripts, that use the Unix 'sed' command, and decode the data
  267. automatically.
  268.  
  269. There is one more rarely used feature of ENCODE: many input files can be
  270. encoded into one large encode file.  The end of an input file is a zero
  271. length encoded line, followed by another "begin" line instead of by an
  272. "end" line.  This decode program will decode this sort of file; but the
  273. encode will only handle a single input file.  This mechanism is rarely
  274. used with UUencoded files but is more common with Base64 encoded
  275. messages.
  276.  
  277.  
  278. FILE LEVEL CHECKSUMS:
  279.  
  280. There are three types of file checksums found in encoded files:
  281.  
  282.        UUENCODE 2.14 and below inserted lines that gave the section
  283.        size and the original input file size.  This is supplanted
  284.        by a better technique in 3.07; but 3.07 UUDECODE still checks
  285.        and validates the old form
  286.  
  287.        UUENCODE 3.07 and Rahul Dhesi's encode scripts compute a Unix
  288.        "sum -r" on the encoded sections and on the original input file.
  289.        A difference is that UUENCODE 3.07 puts the expected "sum -r"
  290.        and size at the end of a file while Rahul''s scripts put them at
  291.        beginning.  This UUDECODE analyzes either.
  292.  
  293.        The third form of checksum is a full 32 bit CRC that Rahul's
  294.        script inserts.  My code does not handle this.  Rahul has written
  295.        the BRIK program to check them.  If there is a "sum -r" failure,
  296.        BRIK analysis should be considered.
  297.  
  298. Several encoders put in a line containing just the original file size.
  299. My uudecode checks these.
  300.  
  301.  
  302. TABLE LINES:
  303.  
  304. Some encoded files but the mapping used at the front of the encoded
  305. file, just in front of the "begin" line.  The format for this is:
  306.  
  307.                    table
  308.                    first 32 characters
  309.                    second 32 characters
  310.  
  311. All this starts in column 1.
  312.  
  313. If decode encounters a table specification, it uses it and overrides any
  314. command line parameters.  Encode will create the table lines if run with
  315. the "-t" parameter.
  316.  
  317.  
  318. COMPLETION CODES:
  319.  
  320. On successful completion, UUDECODE sets ERRORLEVEL to 0.  If there are
  321. any problems, ERRORLEVEL is set to non-zero.
  322.  
  323. The purpose of "-e" is to automatically run an un-archiver (like PKZIP
  324. or ARJ) when UUDECODE successfully completes.  If the "-e" option is
  325. given, UUDECODE calls BAT file UNARCUUE on successful completion;
  326. UNARCUUE is passed five parameters:
  327.  
  328.                 the filename decoded (with path but no extension),
  329.                 the file extension,
  330.                 the input file name  (with path but no extension),
  331.                 the input file extension that is used,
  332.                 the number of sections.
  333.  
  334. Normally the file extension tells which un-archiver to call.  The
  335. UNARCUUE BAT file, can test these parameters and call the necessary
  336. un-archiver.  If UNARCUUE is called, the return code from UUDECODE is
  337. the return code passed back from UNARCUUE.  Note: one user had a problem
  338. in that the routines called by UNARCUUE set the errorlevel to 1 which
  339. was passed back to be the return code from UUDECODE.
  340.  
  341. The "-E" (upper case) option is like "-e" but you supply the name of
  342. the BAT file to execute.
  343.  
  344. If you are running an automated system, the -y or -n options which force
  345. a "Y" or "N" response to messges, may be helpful.
  346.  
  347. Both UUencode and UUdecode can accept command line input from the command
  348. line or from a response file.  A repsonse file is specified on the command
  349. line by preceeding a file name with "@".  The default response file
  350. extension is ".rsp".  Thus
  351.  
  352.         UUDECODE @uuopts @uufile.xyz  out.fil
  353.  
  354. Will first get command line options from the file uupots.rsp, then will
  355. get the input file name from file uufile.xyz, and will put the decoded
  356. result into file out.fil.
  357.  
  358. BUGS and PROBLEMS:
  359.  
  360. I try to make this program as good as possible.  If you find a problem,
  361. please send me a diskette.  You can mail a 3 1/2" diskette in a regular
  362. envelope, with no special protection, with a single stamp.
  363.  
  364.  
  365. CONCLUSION:
  366.  
  367. This works well for me.  On UNIX I find something I want encoded in 3
  368. sections:
  369.               PRG1, PRG2, PRG3.
  370. I copy the three files down to my PC as PRG1.UUE, PRG2.UUE, and PRG3.UUE.
  371. I then just enter UUDECODE PRG and the thing decodes.
  372.  
  373.  
  374. Suggestions appreciated. The programs are written in Turbo Pascal with
  375. about 5% TASM for speed. The source is not public domain.
  376.  
  377. The program is freeware for personnal, private use.  If used in any
  378. other way, please contact me - there is a modest charge.
  379.  
  380. The feature of MIME Base64 decoding is available as a $20 option.
  381.  
  382. Richard Marks (AA3NO)
  383. 931 Sulgrave Lane
  384. Bryn Mawr, PA 19010
  385.  
  386. Copyright (c) Richard E. Marks, Bryn Mawr, PA,
  387.         1992, 1993, 1994, 1995, 1996
  388.  
  389. Also Copyright program name of
  390.      UUENCODE 95, UUDECODE 95, UUCODE 95, UUWIN 95,
  391.      UUENCODE 96, UUDECODE 96, UUCODE 96, UUWIN 96,
  392.      UUENCODE 97, UUDECODE 97, UUCODE 97, UUWIN 97,
  393.      UUENCODE 98, UUDECODE 98, UUCODE 98, UUWIN 98,
  394.      UUENCODE 99, UUDECODE 99, UUCODE 99, UUWIN 99,
  395.      and any other variations of the above specific names followed by
  396.      a year (e.g. UUENCODE 2000)
  397. Copyright (c) by Richard E. Marks, Bryn Mawr, PA 1995, 1996
  398.